home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / refreshIprImage.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.7 KB  |  157 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17.  
  18. global proc refreshIprImage()
  19. //
  20. // Description:
  21. //        Update the entire resolution of the iprImage.
  22. //
  23. {
  24.     string $iprEngine = "defaultIprEngine";
  25.  
  26.     int $fileSizeInMB            = 500;
  27.     int $memoryAvailableInMB    = 50;
  28.  
  29.     
  30.     int $resolution[] = `iprEngine -q -resolution $iprEngine`;
  31.     int $width          = $resolution[0];
  32.     int $height          = $resolution[1];
  33.  
  34.     int $oldRegion[]  = `iprEngine -q -region $iprEngine`;
  35.     int $x1_oldRegion = $oldRegion[0];
  36.     int $y1_oldRegion = $oldRegion[1];
  37.     int $x2_oldRegion = $oldRegion[2];
  38.     int $y2_oldRegion = $oldRegion[3];
  39.     
  40.     int $numPixelsInRegion = 0;
  41.     int $regionIsUpToDate  = 0;
  42.  
  43.     if ($regionIsUpToDate) {
  44.         $numPixelsInRegion = 100;
  45.     }
  46.  
  47.     int $numPixelsToRender = ($width*$height) - $numPixelsInRegion;
  48.  
  49.     // Compute pixel aspect ratio
  50.     if ($width <= 0) {
  51.         error ("Image of resolution " + $width + " " + $height + " is invalid.");
  52.         return;
  53.     }
  54.     float $pixelAspectRatio = (float) $height / (float) $width;
  55.  
  56.     // Compute the number of tiles
  57.     if ($memoryAvailableInMB <= 0) {
  58.         error ("No memory is available to update the image.  Increase the IPR memory limit.");
  59.         return;
  60.  
  61.     }
  62.     float $numberOfTiles = $fileSizeInMB / $memoryAvailableInMB;
  63.     
  64.  
  65.     // Compute the pixels per tile
  66.     if ($numberOfTiles <= 0) {
  67.         warning ("There is nothing to render.");
  68.         return;
  69.     }
  70.     float $pixelsPerTile = $numPixelsToRender / $numberOfTiles;
  71.     
  72.     // Compute the resolution of the tiles
  73.     float $fltXtileSize = sqrt($pixelsPerTile / $pixelAspectRatio);
  74.     float $fltYtileSize = $fltXtileSize * $pixelAspectRatio;
  75.     int $xTileSize = $fltXtileSize;
  76.     int $yTileSize = $fltYtileSize;
  77.  
  78.     print ("Maximum tile size " + $xTileSize + " " + $yTileSize + "\n");
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.     int $x1 = 0;
  89.     int $y1 = 0;
  90.     int $x2 = $xTileSize;
  91.     int $y2 = $yTileSize;
  92.  
  93.  
  94.     int $done = false;
  95.     int $count = 0;
  96.     int $row = 0;
  97.  
  98.     while (!$done) {
  99.  
  100.         int $new_x1 = $x2;
  101.         int $new_x2 = $x2 + $xTileSize;
  102.  
  103.         int $new_y1 = $row*$yTileSize;
  104.         int $new_y2 = $new_y1 + $yTileSize;
  105.         
  106.         if ($new_y2 > $height)
  107.             $new_y2 = $height;
  108.  
  109.         if ($x2 > $width) {
  110.             $x2 = $width;
  111.             $new_x1 = 0;
  112.             $new_x2 = $xTileSize;
  113.  
  114.             $row++;
  115.             $new_y1 = $row*$yTileSize;
  116.             $new_y2 = $new_y1 + $yTileSize;
  117.  
  118.             if ($new_y2 > $height) {
  119.                 $new_y2 = $height;
  120.             }
  121.  
  122.         } 
  123.  
  124.         
  125.         iprEngine -e -region $x1 $y1 $x2 $y2 $iprEngine;
  126.  
  127.         int $startTuningProblem = catch(
  128.             `iprEngine -e -startTuning $iprEngine`);                
  129.         updateIPRMemoryEstimate();
  130.  
  131.         if (!$startTuningProblem) {
  132.             iprEngine -e -u $iprEngine;
  133.             
  134.             if ($x2 == $width && $y2 == $height) {
  135.                 $done = 1;
  136.             }
  137.             
  138.             $x1 = $new_x1;
  139.             $y1 = $new_y1;
  140.             $x2 = $new_x2;
  141.             $y2 = $new_y2;
  142.  
  143.             $count++;
  144.         } else
  145.             break;
  146.     }
  147.  
  148.  
  149.     // Marquee the oldRegion
  150.     iprEngine -e 
  151.         -region $x1_oldRegion $y1_oldRegion $x2_oldRegion $y2_oldRegion
  152.         $iprEngine;
  153.  
  154.     int $startedTuning = catch(`iprEngine -e -startTuning $iprEngine`);
  155.     updateIPRMemoryEstimate();
  156. }
  157.